/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wat.ziszcommon.clientgui;

import java.awt.Component;
import javax.swing.JTabbedPane;

/**
 *
 * @author kubaolszewski
 */
public class MyJTabbedPane extends JTabbedPane{
    
    public MyJTabbedPane(){
        
    }
    
    public void nowy(){
        
    }
    
    public void selected(Component obj){
        int i;
        boolean jest = false;
        String nazwa, nazwa2;
        nazwa = obj.toString();
        Component tempObj;
        for(i=0; i<this.getTabCount(); i++){
            tempObj=this.getComponentAt(i);
            nazwa2=tempObj.toString();
            if (nazwa.equals(nazwa2)){
                jest=true;
                this.setSelectedIndex(i);
                return;
            }
        }
        if(!jest){
            this.addMyTab(obj);
        }
    }
    
    //public void removeMyTab(Component obj){
    //    this.remove(TOP);
    //}
    
    
    public void addMyTab(Component obj){
        int i;
        i=this.getTabCount();
        this.add(obj.toString(), obj);
        this.initTabComponent(i,obj);
        this.setSelectedIndex(i);
        ((MyJPanel)obj).setMyJTabbedPane(this);
    }
    
    private void initTabComponent(int i,Component obj) {
        this.setTabComponentAt(i,
                 new ButtonTabComponent(this,(MyJPanel)obj));
    }
    
    public void removeMyTab(Component obj){
         int i = 0;
         //i=this.indexOfTabComponent(obj);
         i=this.indexOfComponent(obj); 
         if (i != -1) {
                this.remove(i);
            }
    }
}
